package com.njwb.day15.zqzb.job.Test01;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class read {
    public static ArrayList<Phone> phones=new ArrayList<>();
    public static void read(){
        try {
            BufferedReader br=new BufferedReader(new FileReader("src/com/njwb/job/Test01/phone.txt"));
            String line;
            while((line=br.readLine())!=null){
                String[] arr = line.split("\\|");
                System.out.println("分割后字段：" + Arrays.toString(arr)); // 调试打印
                if (arr.length == 4) {
                   String caller=arr[0];
                   String called=arr[1];
                    int duration = Integer.parseInt(arr[2].trim());
                    int time = Integer.parseInt(arr[3].trim());
                    Phone phone = new Phone(caller, called, duration, time);
                    phones.add(phone);
                }
            }




        } catch (FileNotFoundException e) {
            System.out.println("文件未找到！");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("读取文件失败！");
            e.printStackTrace();
        } catch (NumberFormatException e) {
            System.out.println("数字格式错误！");
            e.printStackTrace();
        }


    }
}
